﻿
@using KRM.Core.Library
@model IEnumerable<KRM.Core.NLog>

@{
    ViewBag.Title = "System logs";
    Layout = "~/Views/Shared/_Layout.cshtml";
    int page = 1;

    if (Request.QueryString["p"] != null)
    {
        page = Convert.ToInt32(Request.QueryString["p"]);

    }

    int itemPerPage = 20;
    int pagingCount = Convert.ToInt32(Math.Ceiling(((float)Model.Count() / (float)itemPerPage)));
    var listPaging = Model.OrderByDescending(a => a.Id).Skip((page - 1) * itemPerPage).Take(itemPerPage).ToList();
}
<div id="deleteLogs" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="deletelogs" aria-hidden="true">
    <form action="/logs/deleteall" method="POST">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h5 id="deletebug">Are you sure you want to delete all log?</h5>
        </div>
        <div class="modal-footer">
            <input type="submit" class="btn btn-primary" value="Delete">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
        </div>
    </form>
</div>
<div class="container-fluid">
    @if (Users.Current(User.Identity.Name) != null)
    {
        <p class="btn btn-primary title-create"><i class="icon-remove-sign"></i><a href="#deleteLogs" class="pull-right" role="button" data-toggle="modal"> Clear all</a></p>
        <div class="row-fluid">
            <table class="table table-hover table-bordered table-fix">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Error source</th>
                        <th>
                            Level
                        </th>
                        <th>
                            User error
                        </th>
                        <th>Date create</th>
                        <th>Delete</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in listPaging)
                    {
                        <tr>
                            <td>
                                @Html.DisplayFor(modelItem => item.Id)
                            </td>
                            <td>
                                <a href="/logs/details/@item.Id">@item.ErrorSource</a>
                            </td>
                            <td>
                                @item.Level
                            </td>
                            <td>
                                @item.tblUser.Username
                            </td>
                            <td>
                                @item.DateCreate
                            </td>
                            <td>@Html.ActionLink("Delete", "Delete", new { id = item.Id })</td>
                        </tr>
                    }
                </tbody>
            </table>
            <div class="paging">
                <a href="/logs/index?p=1">«</a>
                <span>
                    @for (int j = page - 3; j <= page + 3; j++)
                    {
                        if (j > 0 && j <= pagingCount)
                        {
                            if (j == page)
                            {
                        <a href="/logs/index?p=@j" class="page-active">@j</a>
                            }
                            else
                            {
                        <a href="/logs/index?p=@j">@j</a>
                            }

                        }
                    }
                </span>
                <a href="/logs/index?p=@pagingCount">»</a>
            </div>
        </div>
    }
    else
    {
        <div class="page-header"></div>
        <p style="text-align: center"><strong>You do not have permission to access this page!</strong></p>
    }
</div>
